package com.devshephard.jucks.ThreadExecutorPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BaseExecutor {
    public static void main(String[] args) {

        ExecutorService executorService1 = Executors.newSingleThreadExecutor();  //使用Executor工具类创建单个线程池
        ExecutorService executorService2 = Executors.newCachedThreadPool();  //使用Executor工具类创建可随线程大小自动扩容的线程池
        ExecutorService executorService3 = Executors.newFixedThreadPool(5);  //使用Executor工具类创建自定义线程数的线程池

        try{
            for (int i = 0; i < 10; i++) {
                executorService3.execute(()->{
                    System.out.println(Thread.currentThread().getName());
                });
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            //线程池使用完成后，需要进行关闭（使用try catch finally 保证线程都执行完毕）
            executorService3.shutdown();
        }
    }
}
